import java.util.*;

public class Parenthesis extends Object {


    public static boolean chkParenthesis(String A, int n) {

        char[] cc = A.toCharArray();
        int i = 0;
        while (i < n){

            while ((cc[i] == '(' && cc[i+1]==')') || (cc[n-1] == ')'&&cc[n-2]=='(')){
                if(cc[i] == '(' && cc[i+1]==')'){
                    i = i + 2;
                }else if(cc[n-1] == ')'&&cc[n-2]=='(') {
                    n = n-2;
                }
            }

            if(cc[i] == '(' &&cc[i+1]=='(' && cc[n-1]==')' &&cc[n-2]==')'){
                i=i+2;
                n=n-2;
            }else {
                return false;
            }



        }
        if(n == i) {
            return true;
        }
        return false;


       /* char[] cc = A.toCharArray();
        Arrays.sort(cc);
        int left = 0;
        int right = 0;
        for (int i = 0; i < cc.length; i++) {
            if(cc[i]=='('){
                left++;
            }
            if(cc[i]==')'){
                right++;
            }
        }
        if(left == right){
            return true;
        }
        return false;*/
       /* for (int i = 0; i < n; i++) {

            if(cc[i] == '(' && cc[i+1] == ')'){
                i++;
                count = count+2;
            }else if(cc[n-1] == ')' && cc[n-2] =='('){
                count =count+2;
                n=n-2;

            } else if(cc[i] == '(' && cc[i+1] == ')'){

                if(cc[n-1] == ')' && cc[n-2] == ')'){
                    n= n-2;
                    i++;
                    count = count+2;
                }else {
                    return false;
                }

            }

        }


        if(count == cc.length){
            return true;
        }
        return false;*/

    }
}